#include "stdafx.h"
#include "log.h"
#include <strsafe.h>

namespace woe
{
#define MAX_LOG_STRING_SIZE 1024
	void LoggerV::log(const short& lvl, const short& label, const char* szFmt, va_list ap)
	{
#ifdef _WIN32
		char buff[MAX_LOG_STRING_SIZE];

		HRESULT hr = StringCchVPrintf( buff, MAX_LOG_STRING_SIZE, szFmt, ap );

		if (FAILED(hr))
		{
			buff[0] = 0;
		}
		Logger::instance()->log(lvl, label, buff);

#else
		char buff[MAX_LOG_STRING_SIZE];
		int hr = vsprintf(buff,ws2s(szFmt).c_str(),ap);
		if(hr < 0)
		{
			buff[0] = 0 ;
		}
		Logger::instance()->log(lvl, label, s2ws(buff).c_str());

#endif
	}


	 void LoggerV::debug(const char* szFmt, ...)
	{
		va_list maker;                               
		va_start( maker, szFmt );

		log(LL_DEBUG, LLB_ALL,szFmt, maker);

		va_end( maker );
	}

	 void LoggerV::warn(const char* szFmt, ...)
	{
		va_list maker;                               
		va_start( maker, szFmt );

		log(LL_DEBUG, LLB_ALL,szFmt, maker);

		va_end( maker );
	}

	 void LoggerV::info(const char* szFmt, ...)
	{
		va_list maker;                               
		va_start( maker, szFmt );

		log(LL_DEBUG, LLB_ALL,szFmt, maker);

		va_end( maker );
	}

	 void LoggerV::error(const char* szFmt, ...)
	{
		va_list maker;                               
		va_start( maker, szFmt );

		log(LL_DEBUG, LLB_ALL,szFmt, maker);

		va_end( maker );
	}

	 void LoggerV::fatal(const char* szFmt, ...)
	{
		va_list maker;                               
		va_start( maker, szFmt );

		log(LL_DEBUG, LLB_ALL,szFmt, maker);

		va_end( maker );
	}

}




